package com.example.demo.controller;

import com.example.demo.model.DemoMessageBean;
import com.example.demo.service.DemoMessageService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@ComponentScan
@Controller
@RequestMapping(value = "message")
public class DemoMessageController {

    @Autowired
    DemoMessageService demoMessageService;

    @RequestMapping(value = "/page")
    @ResponseBody
    public String page() {
        return "";
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public String selectMessage(@RequestParam("lastId") String lastId) {
        List<DemoMessageBean> list = demoMessageService.selectMessage(lastId);
        return new Gson().toJson(list);
    }

    @RequestMapping(value = "/detail")
    @ResponseBody
    public DemoMessageBean getMessageDetail(@RequestParam("id") String id) {
        return demoMessageService.getMessageDetail(id);
    }

}
